
object GCDComputer 
{
    def main() : Unit = 
    {{
        println(new GCD().computeGCD(10,11));
        println(new GCD().computeGCD(1622,8));
        println(new GCD().computeGCD(1846,142));
    }}
}

//This class allows computation of GCD
class GCD 
{
	
	def computeGCD(i : Int, j : Int) : Int = 
	{
		var r : Int;
		
		println("Computing GCD("+i+","+j+")");
		
		r = this.modulo(i,j);
		
		while(0<j || j<0) 
		{
			r = j;
			j = this.modulo(i,j);
			i = r;
		}
		return i;
	}
	
	def modulo(i: Int, j: Int) : Int =
	{
		if(0<i)
		{
			while(j<i || j==i)
			{
				i = i-j;
			}
		} else if(i<0)
		{
			while(i<j || i==j)
			{
				i = i+j;
			}
			i = i-j;
		} else
		{
			i = 0;
		}		
		return i;
	}
}